package com.sdcqjy.property.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sdcqjy.mylibrary.adapter.SuperRecyclerAdapter;
import com.sdcqjy.property.R;
import com.sdcqjy.property.mode.CityMode;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/2/12.
 */
public class SelectCityAdapter extends SuperRecyclerAdapter<CityMode> {
    public SelectCityAdapter(Context context, List<CityMode> modeList) {
        super(context, modeList);
    }

    public int getLayoutId() {
        return R.layout.item_select_city;
    }

    public SuperRecyclerAdapter.ViewHolder<CityMode> getViewHolder(View view) {
        return new ViewHolder(view);
    }

    private CityMode defaultCityMode;

    public CityMode getDefaultCityMode() {
        return defaultCityMode;
    }

    public class ViewHolder extends SuperRecyclerAdapter.ViewHolder<CityMode> implements View.OnClickListener {
        @BindView(R.id.textTitle)
        TextView textTitle;
        @BindView(R.id.imgCheck)
        ImageView imgCheck;
        @BindView(R.id.icon)
        ImageView icon;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            view.setOnClickListener(this);
        }

        public void setData(CityMode mode) {
            super.setData(mode);
            icon.setImageResource(mode.getLocaIcon());
            textTitle.setText(mode.name);
            if (mode.isCheck) {
                defaultCityMode = mode;
                imgCheck.setImageResource(R.drawable.radio_check_blue_);
            } else {
                imgCheck.setImageResource(R.drawable.radio_check_blue);
            }
        }

        public void onClick(View v) {
            if (defaultCityMode != null) defaultCityMode.isCheck = false;
            mode.isCheck = true;
            notifyDataSetChanged();
        }
    }
}
